<script type="text/javascript">
var enable_submit = true;
function submit_snapshot_create() {
    var snapshot_name = $("#volume_snapshot_modal").find("#snapshot_name_cr");
    var bValid = true;
    bValid = bValid && checkRegexp(snapshot_name, /^[0-9a-z-]+$/, "名称应由小写英文字母、数字或中划线(英文)构成。");
    bValid = bValid && checkLength(snapshot_name, "名称", 1, 32);
    if (bValid) {
        if (enable_submit) {
            enable_submit = false;
            var $submitBtn = $('.modal-footer').find('.btn-blue');
            $submitBtn.html('<i class="fa fa-spinner fa-spin" style="margin:3px 6px;"></i>');
            $('.rtn-tip').slideUp('fast');
            $.post("/snapshot_create", {
                "name": "{{volume.pool.name}}/{{volume.name}}@" + snapshot_name.val(),
                "username": "{{volume.username}}",
                "protocol": "{{volume.protocol}}",
                "description": $("#description").val()
            },
            function(data) {
                if (data.reply.is_success) {
                    angular.element('#snapshot_create').scope().close();
                    $('#snapshot_table').trigger("reloadGrid")
                } else {
                    error = data.reply.error;
                    $('.rtn-tip').text(error).slideDown('fast');
                    $submitBtn.html(SelfTranslate("[[ 'label ok'|translate ]]"));
                    enable_submit = true;
                }
            });
        }
    }
}
$(function() {
    var obj = {
        "snapshot_name":"由1到32位小写英文字母、数字、中划线(英文)构成"
    }
    bindMouseEvent('#volume_snapshot_modal',obj);
});
</script>
<div class="modal-header">
    <h3>创建卷快照</h3>
</div>
<div class="modal-body modal-body-height" id="volume_snapshot_modal">
    <div class="snapshot-create-box">
        <div class="rtn-tip"></div>
        <table class="base-info">
            <tr>
                <td>
                    <label>名称</label><a>*</a>
                </td>
                <td colspan="3">
                    <input id="snapshot_name_cr" name="snapshot_name_cr" size="25" type="text" />
                    <i class="fa fa-question-circle" itype="snapshot_name"></i>
                </td>
            </tr>
        </table>
        <table class="base-info">
            <tr>
                <td>
                    <label>快照描述</label>
                </td>
                <td colspan="3">
                    <textarea name="description" id="description" style="width: 100%" rows="3"></textarea>
                </td>
            </tr>
        </table>
    </div>
    <div class="error-tip">
        <p></p><span></span>
    </div>
    <div class="tip">
        <p></p><span></span>
    </div>
</div>
<div class="modal-footer">
    <button class="btn btn-blue" ng-click="ok()">[[ 'label ok'|translate ]]</button>
    <button class="btn btn-white" ng-click="cancel()">[[ 'label cancel'|translate ]]</button>
</div>
